<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
	<!--
	 	- Function BoEmail
	 	- Generic's generation of back-office emailing
	 	- Don't change anything
	-->
	<xsl:template name="BoEmail">
		<xsl:if test="//Statics/Sls/Http/params/param[name='tpl']/value != ''">
			<script type="text/javascript" src="{concat($sls_url_domain,'/Public/Scripts/','ckeditor/ckeditor.js')}"></script>
	        <script type="text/javascript" src="{concat($sls_url_domain,'/Public/Scripts/','ckfinder/ckfinder.js')}"></script>
	        <script type="text/javascript">
	            window.onload = function(){
	                CKEDITOR.basePath = '<xsl:value-of select="concat($sls_url_domain,'/Public/Scripts/','ckeditor/')" />';
	                CKEDITOR.replace("message");
	                CKFinder.setupCKEditor(null,'<xsl:value-of select="concat($sls_url_domain,'/Public/Scripts/','ckfinder/')" />');
	            };
	            <xsl:text disable-output-escaping="yes"><![CDATA[
		            window.addEvent('domready', function(){
		            	$('dynamic_column').addEvent('change', function(e){
		            		if ($('dynamic_column').get('value') != ''){
		            			var content = '||' + $('dynamic_column').get('value') + '||';
		            			var breakObject = CKEDITOR.dom.element.createFromHtml('<span>' + content + '</span>');
		                		var ranges = CKEDITOR.instances.message.getSelection().getRanges(true);
		                		
		                		CKEDITOR.instances.message.fire('saveSnapshot');
		                		
		                		for (var range, i = ranges.length - 1; i >= 0; i--) {
				                    range = ranges[i];
				
				                    if (i < ranges.length - 1) breakObject = breakObject.clone(true);
				
				                    range.insertNode(breakObject);
				                    if (i == ranges.length - 1) {
				                        range.moveToPosition(breakObject, CKEDITOR.instances.message.POSITION_AFTER_END);
				                        range.select();
				                    }
				                }
			
			                	CKEDITOR.instances.message.fire('saveSnapshot');
		                		
		            			$('dynamic_column').set('value','');
		            		};
		            	});
		            });
		    	]]></xsl:text>
	        </script>
	        <style type="text/css">
	            .cke_skin_kama {
	                display: block;
	                float: left;
	                margin-left:20px;
	            }
	        </style>
	    </xsl:if>
		<h1 class="main"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_title'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template>&#160;<span class="light"><xsl:value-of select="//View/bo_actions/bo_action[selected = 'true']/label" /></span></h1>
		<form action="" method="post" enctype="">
			<div class="grey_wrapper_no_padding">
				<ul class="langs"></ul>
				<div class="edit_form">
					<xsl:choose>
						<xsl:when test="//View/tpl_choose = 'true'">						
							<input type="hidden" name="reload_email" value="true" />
							<input type="hidden" name="tpl" value="{//View/infos/tpl}" />
							
							<xsl:if test="count(//View/errors/error) &gt; 0">
								<ul class="error">
									<xsl:for-each select="//View/errors/error">
										<li><xsl:value-of select="." disable-output-escaping="yes" /></li>
									</xsl:for-each>
								</ul>
							</xsl:if>
							<xsl:if test="//View/success != ''">
								<div class="success">
									<xsl:value-of select="//View/success" disable-output-escaping="yes" />
								</div>
							</xsl:if>
							
							<div class="row">
								<label for="from_name"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_from_name'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<input type="text" class="text" name="from_name" id="from_name" value="{//View/infos/from_name}" />
							</div>
							<div class="row">
								<label for="from_email"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_from_email'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<input type="text" class="text" name="from_email" id="from_email" value="{//View/infos/from_email}" />
							</div>
							<div class="row">
								<label for="reply_name"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_reply_name'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<input type="text" class="text" name="reply_name" id="reply_name" value="{//View/infos/reply_name}" />
							</div>
							<div class="row">
								<label for="reply_email"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_reply_email'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<input type="text" class="text" name="reply_email" id="reply_email" value="{//View/infos/reply_email}" />
							</div>
							<div class="row">
								<label for="return_name"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_return_name'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<input type="text" class="text" name="return_name" id="return_name" value="{//View/infos/return_name}" />
							</div>
							<div class="row">
								<label for="return_email"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_return_email'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<input type="text" class="text" name="return_email" id="return_email" value="{//View/infos/return_email}" />
							</div>
							<div class="row">
								<label><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_to'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<span class="warn" style="text-align:left;">
									<xsl:for-each select="//View/infos/recipients/recipient">
										<strong><xsl:value-of select="." /></strong><xsl:if test="position() != last()">, </xsl:if>
									</xsl:for-each>
								</span>
							</div>
							<div class="row">
								<label for="subject"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_subject'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<input type="text" class="text" name="subject" id="subject" value="{//View/infos/subject}" />
							</div>
							<div class="row">
								<label for="dynamic_column"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_dynamic'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<select name="dynamic_column" id="dynamic_column">
									<option value=""><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_dynamic_choose'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></option>
									<xsl:for-each select="//View/columns/column">
										<option value="{name}"><xsl:value-of select="comment" /></option>
									</xsl:for-each>
								</select>
							</div>
							<div class="row">
								<label for="message"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_email_message'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></label>
								<textarea name="message" id="message" cols="" rows="">
									<xsl:choose>
										<xsl:when test="//View/infos/message = ''">									
											<xsl:value-of select="//View/templates/template[id=//View/infos/tpl]/header" />
											<xsl:value-of select="//View/templates/template[id=//View/infos/tpl]/footer" />
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="//View/infos/message" />
										</xsl:otherwise>
									</xsl:choose>
								</textarea>
							</div>
						</xsl:when>
						<xsl:otherwise>
							<h3>Before writing your message, choose your email template</h3>
							<div class="row">
								<label for="tpl">Template</label>
								<select name="template" id="tpl">
									<xsl:for-each select="//View/templates/template">
										<option value="{id}">
											<xsl:value-of select="id" />
										</option>
									</xsl:for-each>
								</select>
							</div>
						</xsl:otherwise>
					</xsl:choose>
				</div>
			</div>
			<div class="form_validator">
				<div class="login_submit">
					<div class="left"></div>
					<div class="middle">
						<input type="submit">
							<xsl:attribute name="value"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="'sls_bo_generic_submit'" /><xsl:with-param name="escaping" select="'yes'" /></xsl:call-template></xsl:attribute>
						</input>
					</div>
					<div class="right"></div>
				</div>
			</div>
		</form>
	</xsl:template>
</xsl:stylesheet>